package com.iwe.crm.workbench.controller;

import com.iwe.crm.base.util.CommonUtil;
import com.iwe.crm.user.bean.User;
import com.iwe.crm.workbench.bean.StageVo;
import com.iwe.crm.workbench.service.TranService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tran")
public class TranController {

    @Autowired
    private TranService tranService;

    @PostMapping("/queryCustomerName")
    public List<String> queryCustomerName(String customerName){
        return tranService.queryCustomerName(customerName);
    }

    //选中阶段，查询可能性
    @GetMapping("/queryPossibility")
    public String queryPossibility(String stage, HttpSession session){
        Map<String,String> stage2PossibilityMap =
                (Map<String, String>) session.getServletContext().getAttribute("stage2PossibilityMap");
        return stage2PossibilityMap.get(stage);
    }

    //查询交易的阶段图标
    @GetMapping("/queryStages")
    public Map<String,Object> queryStages(String id,Integer index, HttpSession session){
        User user = CommonUtil.getCurrentUser(session);
        Map<String,String> stage2PossibilityMap =
                (Map<String, String>) session.getServletContext().getAttribute("stage2PossibilityMap");
      return tranService.queryStages(id,stage2PossibilityMap,index,user);
    }
}
